#!/usr/bin/env python
# coding: utf-8
import web
from config import settings
from datetime import datetime

render = settings.render
db = settings.db

class hello:

    def GET(self):
        return 'Hello, Feed!'


class redirect:

    def GET(self, path):
        web.seeother('/' + path)


class index:

    def GET(self):
        blogInfo = db.select('blog_info', what='BID, Blog_Title, Blog_Link, Blog_LastBuildDate, Blog_Feed', where=' 1', order='Blog_LastBuildDate DESC')
        newPosts = db.select('post_into', what='Pid, Post_Title, Post_Link, Post_Content', where = ' 1', order='Pid DESC', limit=20)
        return render.index(blogInfo = blogInfo, newPosts = newPosts)


class readOne:

    def GET(self, postId):
        postInfo = db.select('post_into', where = 'Pid = ' + postId, limit=1)
        return render.readpost(postInfo = postInfo[0])

class readRSS:
    
    def GET(self, blogId):
        blogInfo = db.select('blog_info', what='Blog_Title, countNUM', where='BID = ' + blogId, limit = 1)
        postInfo = db.select('post_into', what = '*', where = 'BID = ' + blogId, order = 'Pid DESC', limit = 10)
        return render.readRss(blogInfo = blogInfo[0], postInfo = postInfo)

#'SELECT * FROM `post_into` WHERE `BID` =' . $BID . ' ';
#SELECT * FROM `post_into` WHERE `Pid` =100658 LIMIT 0 , 1



class listx:
    def GET(self, name):
        return "Listing info about user: {0}".format(name)
